// pages/rechargecar/rechargecar.js
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    According: false,
    navindex: 0,
    buycarnav: [
      { txt: '待发货' },
      { txt: '待收货' },
      { txt: '已完成' },
    ],
    tempStatus:0
  },
  click: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    that.setData({
      tempStatus: id,
      navindex:id,
      orderlist:[]
    })

    that.initData();
     
  },
  confirmHs:function(e){
    let oid = e.currentTarget.dataset.oid;
    let that = this;
    wx.showModal({
      title: '温馨提示:',
      content: '您确定收货成功吗?',
      success: function (res) {
        if (res.cancel) {
          //点击取消,默认隐藏弹框
        } else {
          wx.showLoading();
          util.commonRequest('orderConfirmSh', 'post', { oid:oid}, function (res) {
            wx.hideLoading();
            var data = res.data;
            if (data.code == 200) {
              that.setData({
                orderlist: []
              })
              that.initData();
            }
            else {
              wx.showToast({
                icon: 'none',
                title: data.msg,
              })
            }
          });
        }
      },
    })
  },
  initData:function(){
    var that = this;
    var param = {
      status: that.data.tempStatus
    };
  
    wx.showLoading({})
    util.commonRequest('buyingOrdelist', 'post', param, function (res) {
      wx.hideLoading();
      if (res.data.code == 200) {
        console.log(res.data.data)
        that.setData({
          orderlist: res.data.data,
        })
      } else {
        wx.showToast({
          icon: 'loading',
          title: res.data.msg,
        })
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.initData();
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    var HQgoods = that.data.rechargecar;
    if (HQgoods.length == 0) {
      that.setData({
        According: true,
      })
    } else {
      that.setData({
        According: false,
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})